package com.wanxi.servlet;

import com.wanxi.model.CompanyModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.ProductModel;
import com.wanxi.service.CompanyService;
import com.wanxi.service.NavService;
import com.wanxi.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/company")
public class CompanyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//   1.乱码处理
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
//        2.拿到前端的值
//        3.将前端的值封装到对象
//        4.调用服务逻辑层
        CompanyService companyService=new CompanyService();
        CompanyModel companyModel=companyService.getCompanyModel();

        NavService navService=new NavService();
        List<NavModel> navModelList=navService.getNavModelList();

        ProductService productService = new ProductService();
        List<ProductModel> productModelList = productService.getProductModelListForCompanyPage();
//        req.setAttribute("phone","028-99999999");
//        req.setAttribute("logo", "../img/logo_g0yv.jpg");
//        5.将数据得到存入req，并转发到页面
        req.setAttribute("companyModel",companyModel);

        req.setAttribute("navModelList",navModelList);
        req.setAttribute("productModelList", productModelList);
        req.getRequestDispatcher("/jsp/company.jsp").forward(req, resp);
    }
}
